﻿using MediatR;
using RBAC.ApiWrites.Applocation.Command;
using RBAC.Domain.RbacEntity;
using RBAC.Infrasturcture.Interfaces;
using RBAC.ResultCode;

namespace RBAC.ApiWrites.Applocation.Commandhandler
{
    public class AddPermissionCommandhandler : IRequestHandler<AddPermissionCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Permission> pemissionrepository;

        public AddPermissionCommandhandler(IBaseRepository<Permission> pemissionrepository)
        {
            this.pemissionrepository = pemissionrepository;
        }
        public async Task<ApiResult<int>> Handle(AddPermissionCommand request, CancellationToken cancellationToken)
        {

            var info = new Permission();
            info.PermissionUrl = request.PermissionUrl;
            info.PermissionPath = request.PermissionPath;
            info.PermissionName = request.PermissionName;


            return new ApiResult<int>()
            {
                Code=ApiResultEnum.新增成功,
                Message = ApiResultEnum.新增成功.ToString(),
                Data= await pemissionrepository.AddAsync(info)
            };
        }
    }
}
